package commands;

import utils.ITransmittable;
import nanoxml.XMLElement;

/**
 * This command represents a chat message between clients.
 */
public class CommandChatMessage implements ITransmittable {

	private final static String ATTR_USER_NAME = "Username";
	
	private String chatMessage = null;
	private String fromUsername = null;

	public CommandChatMessage (String chat) {
		this.chatMessage = chat;
	}

	public CommandChatMessage (XMLElement message) {

		this.chatMessage = message.getContent();
		this.fromUsername = (String) message.getAttribute(ATTR_USER_NAME);
	}
	
	public XMLElement toXML () {
		XMLElement message = new XMLElement();
		message.setName(Commands.CHAT_MESSAGE);
		message.setContent (chatMessage);
		if (fromUsername != null) {
			message.setAttribute(ATTR_USER_NAME, fromUsername);
		}
		return message;
	}
	public String getChat() {
		return chatMessage;
	}
	public String getUsername() {
		return fromUsername;
	}
	public void setUsernameFrom(String fromUsername) {
		this.fromUsername = fromUsername;
	}
}